<?php
require './vendor/autoload.php';
use Anker1992\BasicLib\MysqlPDO;

$db = MysqlPDO::getInstance([
    'hostname' => '127.0.0.1',
    'port' => 8889,
    'database' => 'test',
    'username' => 'root',
    'passport' => 'root'
]);

//查询
/**

$value = $db->query("select * from person where user_id = ?", 9);
var_dump($value);

 */

//插入（不推荐）
/**

$ret = $db->exec("insert into person(`user_id`, `username`, `sex`, `email`) 
values(null, 'stu01', 'man', '11234@qq.com')");
if ($ret) {
    echo 'insert success!';
}

 */

//插入（推荐）
/**

$data = array(
    'user_id' => null,
    'username' => 'anker',
    'sex' => 'female',
    'email' => 'test@qq.com'
);
$ret = $db->insert("person", $data);
if ($ret) {
    echo 'insert success! insertid is '. $ret;
}

 */

//更新
/**

$data = array(
    'username' => 'ankerNiu',
    'sex' => 'female',
    'email' => 'anker@qq.com'
);
$db->where('user_id>=', 5);
$db->where('sex', 'man');
$ret = $db->update("person", $data);
if ($ret) {
    echo "update success!";
}

 */

 //获取一行数据
/**

 $ret = $db->getOne("select * from  person where user_id = ?", 9);
 var_dump($ret);

 */